-- hp_to_skill
-- created by wangy
-- 生命低于%，施放技能

return {
    apply = function(prop, baseValue)
        return prop[3];
    end,
    -- 触发
    trigger = function(who, prop, arg)
        local hp    = who:queryAttrib("hp");
        local endHp = math.modf(who:queryAttrib("max_hp") * prop[3] / 1000);

        if hp > endHp then
            return 0;
        end

        if who.hpToSkill then
            return 0;
        end

        local skillId = tonumber(prop[2]);

        -- 触发技能
        local round = CombatM.getRound();
        -- 记录施放技能的回合
        who.skill_round = round + 1;
        SkillM.apply(who, ME.user, skillId, round);

        -- 标志已经复活过了
        who.hpToSkill = true;
    end,

    desc = function(prop)
        local row = PropM.getRow(prop[1]);
        local desc = row.desc;
        local skillName = SkillM.query(tonumber(prop[2]), "name");

        desc = string.gsub(desc, "{0}", skillName);

        return string.gsub(desc, "{1}", tonumber(prop[3] / 10));
    end,

    record = function(target, prop, path)
        return false;
    end
};
